package org.liuqm.servlet;

import com.alibaba.fastjson.JSONObject;
import org.liuqm.common.AjaxResult;
import org.liuqm.filter.RequestMapping;
import org.liuqm.filter.RequestParam;
import org.liuqm.pojo.Auctionuser;
import org.liuqm.service.IAuctionuserService;
import org.liuqm.service.impl.AuctionuserServiceImpl;

import java.util.UUID;

@RequestMapping("/auth")
public class AuthController {

    IAuctionuserService auctionuserService;

    public AuthController() {
        auctionuserService = new AuctionuserServiceImpl();
    }

    @RequestMapping("/login")
    public AjaxResult login(@RequestParam(name = "username") String username, @RequestParam(name = "password") String password) {
        AjaxResult result = null;
        JSONObject json = new JSONObject();

        Auctionuser auctionuser = auctionuserService.getAuctionuser(username, password);

        if (auctionuser != null) {
            result = AjaxResult.success("登录成功");
            String token = UUID.randomUUID().toString();
            json.put("access_token", token);
            result.setData(json);

        } else {
            result = AjaxResult.error("账号或密码不存在！");
        }

        return result;

    }


    @RequestMapping("/logout")
    public AjaxResult logout() {
        return AjaxResult.success("退出成功！");

    }


}
